package com.quanquan.store.repository.marketActivity.paperPlane;

import com.quanquan.store.entity.marketActivity.paperPlane.PaperPlaneRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @ClassName PaperPlaneRecordRepository
 * @Description
 * @Author Owen
 * @Date 2019/9/27 0027 上午 9:37
 * @Version V1.0
 **/
public interface PaperPlaneRecordRepository extends JpaRepository<PaperPlaneRecord,Long> {

    @Query(value = "select * from oo_paper_plane_record where activity_id=?1 GROUP BY user_id,coupon_id",nativeQuery = true)
    List<PaperPlaneRecord> findAllByActivityId(Long activityId);

    @Query(value = "select sum(gift_count) from oo_paper_plane_record where activity_id=?1 and user_id=?2 and coupon_id=?3",nativeQuery = true)
    int sumGiftCount(Long activityId, String userId, String couponId);
}
